////////////////////////////////////////////////////////////////////////////////
//
//  MICROSOFT CORPORATION
//  Copyright (c) Microsoft Corporation.
//  All Rights Reserved.
//
//  NOTICE: Microsoft Confidential. Intended for Internal Use Only.
//
////////////////////////////////////////////////////////////////////////////////

package com.msn.beet.logging
{

import flash.errors.IllegalOperationError;

/**
 * Enumerated class for defining log levels. Valid levels are DEBUG, INFO, WARN,
 * ERROR, FATAL and OFF
 */
public final class LogLevel
{
    include "../core/Version.as";

    public static const DEBUG:LogLevel = new LogLevel(0, "DEBUG");
    public static const INFO:LogLevel  = new LogLevel(1, "INFO");
    public static const WARN:LogLevel  = new LogLevel(2, "WARN");
    public static const ERROR:LogLevel = new LogLevel(3, "ERROR");
    public static const FATAL:LogLevel = new LogLevel(4, "FATAL");
    public static const OFF:LogLevel   = new LogLevel(5, "OFF");

    /**
     * Evaluates a string and returns the matching log level.
     * @param evalString the string representing log levels DEBUG, INFO,
     *                   WARN, ERROR, FATAL and OFF
     * @return an instance of that log level if found
     * @throws RangeError if type is not found from string
     */
    public static function fromString(evalString:String):LogLevel
    {
        evalString = evalString.toUpperCase();

        if (LogLevel[evalString] is LogLevel)
        {
            return LogLevel[evalString];
        }
        else
        {
            throw new RangeError(
                "\"" + evalString + "\" is not a valid log level.");
        }
    }

    private static var lock:Boolean = false;
    {
        lock = true; // static code block
    }

    private var _name:String;
    private var _value:int;

    /**
     * Virtual private constructor.
     */
    public function LogLevel(level:int, name:String)
    {
        if (lock)
        {
            throw new IllegalOperationError("Invalid enum construction.");
        }

        this._value = level;
        this._name = name;
    }

    /**
     * The integer value of the log level.
     * @return
     */
    public function get value():int
    {
        return this._value;
    }

    /**
     * The string value of the log level.
     * @return
     */
    public function get name():String
    {
        return this._name;
    }

}

}
